The NHibernate designer can create migrations for you. Migrations are created as source code which you can edit to reflect additional actions, conditional logic and overridden behaviour. Your model will give rise to a sequence of migrations as it evolves over time. Migrations are collected together in a migrations project separate from your application and model code.

Selecting the Migrations Project

Because migrations are created as C# or Visual Basic source code, they are stored in a Visual Studio project. You need to specify on your model which project it should store its migrations in.

To do this:

Don’t use the same migrations project for multiple models.
 

Creating a Migration

To create a migration, select the Migrations menu and choose Create Migration.

NHibernate displays the actions required in the Up method to migrate the database from the last migration to the current model design, and the actions required in the Down method to reverse the process. You can de-select any actions that you don’t want generated for you.

Enter a migration name and optionally a description. The migration name will be the name of the generated class and must be a valid class name in the migration project language.

Click OK. NHibernate Designer generates and displays the migration class. You can now edit this class if required.

NHibernate Designer stores snapshots of your model in the migrations project, and uses these to work out what has changed. Do not move, delete or rename these snapshots!